<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>库存</title>
    <% include("../layout/css.html"){} %>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card card-box-shadow">
    	<div class="layui-card-body">
	        <div class="layui-form toolbar">
	            <div class="layui-form-item">
	                <div class="layui-inline">
	                    <label class="layui-form-label w-auto">搜索：</label>
	                    <div class="layui-input-inline mr0">
	                        <input name="warehouseName" class="layui-input" type="text" placeholder="仓库,产品,规格"/>
	                    </div>
	                </div>
	                <div class="layui-inline">
	                    <button class="layui-btn icon-btn" lay-filter="searchSubmit" type="button" lay-submit>
	                        <i class="layui-icon">&#xe615;</i>搜索
	                    </button>
	                    <!--<% if(so.hasPermission("productStorage:add")){ %>
	                    <button id="btnAdd" type="button" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
	                    <% } %>-->
	                </div>
	            </div>
	        </div>
        	<table class="layui-table" id="productStorageTable" lay-filter="productStorageTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBar">
	<% if(so.hasPermission("productStorage:update")){ %>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <% } %>
    <% if(so.hasPermission("productStorage:delete")){ %>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <% } %>
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="modelProductStorage">
    <form id="modelProductStorageForm" lay-filter="modelProductStorageForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <input name="companyId" type="hidden"/>
        <div class="layui-form-item layui-row">
           <div class="layui-col-md4">
               <label class="layui-form-label">仓库</label>
               <div class="layui-input-block">
                   <input  id="warehouseName" name="warehouseName"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入仓库"/>
               </div>
               <label class="pageSel" id="warehouseSel">选择</label>
           </div>
           <div class="layui-col-md4">
               <label class="layui-form-label">产品</label>
               <div class="layui-input-block">
                   <input  id="productName" name="productName"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="required" placeholder="请输入产品"/>
               </div>
               <label class="pageSel" id="productSel">选择</label>
           </div>
           <div class="layui-col-md4">
               <label class="layui-form-label">规格</label>
               <div class="layui-input-block">
                   <input  id="specification" name="specification"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="required" placeholder="请输入规格"/>
               </div>
           </div>
        </div>
        <div class="layui-form-item layui-row">
           <div class="layui-col-md4">
               <label class="layui-form-label">长度</label>
               <div class="layui-input-block">
                   <input  id="lengths" name="lengths"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="required|numberXZ" placeholder="请输入长度"/>
               </div>
           </div>
           <div class="layui-col-md4">
               <label class="layui-form-label">负差</label>
               <div class="layui-input-block">
                   <input  id="negative" name="negative"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="required|numberX" placeholder="请输入负差"/>
               </div>
           </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">理算重量</label>
                <div class="layui-input-block">
                    <input  id="liWeight" name="liWeight"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="numberXZ" placeholder="请输入理算重量"/>
                </div>
            </div>
           <!--<div class="layui-col-md4">
               <label class="layui-form-label">数量</label>
               <div class="layui-input-block">
                   <input  id="num" name="num"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="required|numberXZNotZero" placeholder="请输入数量"/>
               </div>
           </div>-->
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">数量</label>
                <div class="layui-input-block">
                    <input  id="num" name="num"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="numberXZ" placeholder="请输入数量"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">理算总重量</label>
                <div class="layui-input-block">
                    <input  id="liTotalWeight" name="liTotalWeight"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="numberXZ" placeholder="请输入实际重量"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input  id="price" name="price"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="numberXZ" placeholder="请输入价格"/>
                </div>
            </div>

        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">材质</label>
                <div class="layui-input-block">
                    <input  id="model" name="model"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="" placeholder="请输入材质"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">产地</label>
                <div class="layui-input-block">
                    <input  id="locality" name="locality"  type="text" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="" placeholder="请输入产地"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input  id="orderNum" name="orderNum"  type="number" class="layui-input"  autocomplete="off"
                            lay-verType="tips" lay-verify="required|numberXZ" placeholder="请输入排序"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-row">
            <div class="layui-col-md8">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                   <textarea placeholder="请输入备注" class="layui-textarea" lay-verType="tips" lay-verify=""
                             id="remark" name="remark" cols="" rows="5" maxlength="255"></textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
            <button class="layui-btn" lay-filter="modelProductStorageSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<% include("../layout/js.html"){} %>
<script type="text/javascript">
    layui.use(['layer', 'form', 'formX','table', 'util', 'admin', 'zTree', 'tableX','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var tableX = layui.tableX;
        var laydate = layui.laydate;
        var formX = layui.formX;

        // 渲染表格
        var insTb = tableX.render({
            elem: '#productStorageTable'
            ,url: 'productStorage/list'
            ,page: true
            ,toolbar: true
            ,cellMinWidth: 100
            ,cols: [[
                {type: 'numbers'}
                ,{field: "warehouseName", minWidth: "60", title: "仓库名称", sort: true, hide:false,totalRowText: '合计' }
                ,{field: "productName", minWidth: "60", title: "产品名称", sort: true, hide:false }
                ,{field: "specification", minWidth: "60", title: "规格", sort: true, hide:false }
                ,{field: "lengths", minWidth: "60", title: "长度", sort: true, hide:false }
                ,{field: "negative", minWidth: "60", title: "负差", sort: true, hide:false }
                ,{field: "num", minWidth: "60", title: "数量", sort: true, hide:false }
                ,{field: "liWeight", minWidth: "60", title: "理算重量", sort: false, hide:false }
                ,{field: "liTotalWeight", minWidth: "60", title: "理算总重量", sort: true, hide:false }
                ,{field: "price", minWidth: "60", title: "价格", sort: true, hide:true }
                ,{field: "model", minWidth: "60", title: "材质", sort: true, hide:true }
                ,{field: "locality", minWidth: "60", title: "产地", sort: true, hide:true }
                ,{field: "orderNum", minWidth: "60", title: "排序", sort: true, hide:true }
                ,{field: "remark", minWidth: "60", title: "备注", sort: true, hide:true }
                ,{field: "createTime", minWidth: "60", title: "创建时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "createUser", minWidth: "60", title: "创建人", sort: true, hide:true }
                ,{field: "updateTime", minWidth: "60", title: "更新时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "updateUser", minWidth: "60", title: "更新人", sort: true, hide:true }
                ,{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
            ]],
            totalRow: {
            }
        });

        // 添加
        $('#btnAdd').click(function () {
            showEditModel();
        });

        // 搜索
        form.on('submit(searchSubmit)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
        });

        // 工具条点击事件
        table.on('tool(productStorageTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(obj);
            }
        });

        // 删除
        function doDel(obj) {
            layer.confirm('确定要删除“' + obj.data.productName + '”库存吗？', {
                shade: .1,
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                $.post('productStorage/delete', {
                    ids: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload();
                        //obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }

        // 显示编辑弹窗
        function showEditModel(mProductStorage) {
            admin.open({
                type: 1,
                maxmin:true,
                closeBtn:1,
                resize: true,
                area:["1000px","500px"],
                title: (mProductStorage ? '修改' : '添加') + '库存',
                content: $('#modelProductStorage').html(),
                success: function (layero, dIndex) {
                    var url = mProductStorage ? 'productStorage/update' : 'productStorage/add';
                    formX.formVal('modelProductStorageForm', mProductStorage);  // 回显数据

                    $("#warehouseSel").hide();
                    $("#productSel").hide();
                    $("#warehouseName").attr("readonly","readonly");
                    $("#productName").attr("readonly","readonly");
                    $("#specification").attr("readonly","readonly");
                    $("#lengths").attr("readonly","readonly");
                    $("#num").attr("readonly","readonly");
                    $("#negative").attr("readonly","readonly");
                    $("#liWeight").attr("readonly","readonly");
                    $("#liTotalWeight").attr("readonly","readonly");
                    $("#price").attr("readonly","readonly");
                    // $("#model").attr("readonly","readonly");
                    // $("#locality").attr("readonly","readonly");

                    // 表单提交事件
                    form.on('submit(modelProductStorageSubmit)', function (data) {
                        layer.load(2);
                        $.post(url, data.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload();
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
						$("button[lay-filter='modelProductStorageSubmit']").attr("disabled","disabled");
                        setTimeout(function(){$("button[lay-filter='modelProductStorageSubmit']").removeAttr("disabled");}, 1000 );
                        return false;
                    });
                    $("#warehouseSel").click(function(){
                        var layindex_t1 = admin.open({
                            type: 2,
                            content:"${ctxPath}/storage/warehouse/listSel?id="
                                +$("#warehouseId").val()+"&name="+$("#warehouseName").val(),
                            maxmin: true,
                            resize: true,
                            area: ["1000px", "540px"],
                            title: '请选择仓库',
                            success: function (layero, dIndex) {
                            }
                        });
                        //layer.full(layindex_t1);
                    });
                    $("#productSel").click(function(){
                        var layindex_t1 = admin.open({
                            type: 2,
                            content:"${ctxPath}/storage/product/listSel?id="
                                +$("#productId").val()+"&name="+$("#productName").val()
                                +"&specification="+$("#specification").val(),
                            maxmin: true,
                            resize: true,
                            area: ["1000px", "540px"],
                            title: "请选择产品",
                            success: function (layero, dIndex) {
                            }
                        });
                        //layer.full(layindex_t1);
                    });
                }
            });
        }
        top.warehouseSel = function(data_sel){
            var t_data = data_sel[0];
            // $("#warehouseId",window.top.document).val(t_data.id);
            // $("#warehouseName",window.top.document).val(t_data.name);
            $("#warehouseName").val(t_data.name);
        }
        top.productSel = function(data_sel){
            var t_data = data_sel[0];
            $("#productName").val(t_data.name);
            if(t_data.specification!=undefined && t_data.specification!=""){
                $("#specification").val(t_data.specification);
            }
            if(t_data.liWeight!=undefined && t_data.liWeight!=""){
                $("#liWeight").val(t_data.liWeight);
            }
        }
        top.productStorageTableReload = function(data_sel){
            insTb.reload();
        }
    });
</script>
</body>
</html>
